// pages/restaurant/components/select/select.js
Component({
  options: {
    multipleSlots: true
  },
  /**
   * 组件的属性列表
   */
  properties: {
    options: {
      type: Array,
      value: []
    },
    fold: {
      type: Boolean,
      value: false
    },
    dropDownIcon: {
      type: String,
      value: "https://rzico.oss-cn-shenzhen.aliyuncs.com/dinnerBar/canyin/canyin-xialakuang.png"
    },
    title:{
      type:String,
      value:''
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    foldState: false,
    lastFoldState: false,
    maxDisplay: 4,
    current: 0,
    promptText: "",
    optionsForm:[]
  },
  observers: {
    'fold': function (fold) {
      this.setData({
        lastFoldState: this.data.foldState,
        foldState: fold
      })
    },
    'options': function (options) {
      this.data.optionsForm = options
      let _data = this.data;
      this.setData({
        maxDisplay: _data.optionsForm.length,
        optionsForm:_data.optionsForm
      })
    },
    'title':function(title){
      this.setData({
        promptText:title
      })
    }
  },
  /**
   * 在组件实例进入页面节点树时执行
   */
  attached: function () {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    changeFoldState() {
      let _lastFoldState = !this.data.lastFoldState
      this.setData({
        foldState: _lastFoldState,
        lastFoldState: _lastFoldState,
      })
    },
    switchOption(e) {
      this.setData({
        promptText: this.data.optionsForm[e.target.dataset.index]
      })
      this.triggerEvent("change", this.data.promptText)
    },

  }
})
